//
//  StatusOriginalView.swift
//  sinaWeibo
//
//  Created by liii on 16/7/24.
//  Copyright © 2016年 liii. All rights reserved.
//

import UIKit
import SnapKit
import SDWebImage

let StatusCellMargin:CGFloat = 10

class StatusOriginalView: UIView {
    
    var status: Status? {
        didSet {
            // 绑定模型数据
            iconView.sd_setImageWithURL(status?.user?.headImageURL)
            vertified_image.image = status?.user?.verified_type_image
            nameLabel.text = status?.user?.name
            mbrank.image = status?.user?.mbrank_image
            timeLabel.text = status?.created_at
            sourceLable.text = status?.source
            contenLabel.text = status?.text
            
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        // 构建UI界面
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    private func setupUI() {
        
        // 添加子控件
        addSubview(iconView)
        addSubview(vertified_image)
        addSubview(nameLabel)
        addSubview(mbrank)
        addSubview(timeLabel)
        addSubview(sourceLable)
        addSubview(contenLabel)
        
        // 约束子控件
        iconView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.snp_top).offset(StatusCellMargin)
            make.left.equalTo(self.snp_left).offset(StatusCellMargin)
            make.width.equalTo(36)
            make.height.equalTo(36)
        }
        vertified_image.snp_makeConstraints { (make) -> Void in
            make.right.equalTo(iconView.snp_right)
            make.bottom.equalTo(iconView.snp_bottom)
        }
        nameLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(iconView.snp_top)
            make.left.equalTo(iconView.snp_right).offset(StatusCellMargin)
        }
        mbrank.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(nameLabel.snp_top)
            make.left.equalTo(nameLabel.snp_right).offset(StatusCellMargin)
        }
        timeLabel.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(iconView.snp_bottom)
            make.left.equalTo(iconView.snp_right).offset(StatusCellMargin)
        }
        sourceLable.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(timeLabel.snp_top)
            make.left.equalTo(timeLabel.snp_right).offset(StatusCellMargin)
        }
        contenLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(iconView.snp_bottom).offset(StatusCellMargin)
            make.left.equalTo(iconView.snp_left)
            make.right.equalTo(self.snp_right).offset(-StatusCellMargin)
        }
        
        // 头像圆角处理
        iconView.layer.cornerRadius = 18
        iconView.layer.masksToBounds = true
        
        // 原创微博的高度计算
        self.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(contenLabel.snp_bottom).offset(StatusCellMargin)
        }
    }
    
    // 头像
    private lazy var iconView: UIImageView = UIImageView(image: UIImage(named: "avatar_default_big"))
    // 会员图标
    private lazy var mbrank: UIImageView = UIImageView(image: UIImage(named: "common_icon_membership"))
    // 认证类型
    private lazy var vertified_image: UIImageView = UIImageView(image: UIImage(named: "avatar_vip"))
    
    // 昵称
    private lazy var nameLabel: UILabel = UIFactory.labelWithText("新浪微博测试", textColor: UIColor.darkGrayColor(), fontSize: 15)
    // 发布时间
    private lazy var timeLabel: UILabel = UIFactory.labelWithText("2016-7-24", textColor: UIColor.darkGrayColor(), fontSize: 11)
    // 微博来源
    private lazy var sourceLable: UILabel = UIFactory.labelWithText("测试来源", textColor: UIColor.darkGrayColor(), fontSize: 11)
    // 微博内容
    private lazy var contenLabel: UILabel = UIFactory.labelWithText("测试数据测试数据测试数据测试数据测试数据数据测试数据测试数据测试数据数据测试数据测试数据测试数据数据测试数据测试数据测试数据数据测试数据测试数据测试数据", textColor: UIColor.darkGrayColor(), fontSize: 15, alignment: .Left)
    
}
